/**
 * @description 商品列表增删改查 api 路由
 * @author LI
 */

const router = require('koa-router')()
const {
  getGoodPhotosAll,
  addGoodPhoto,
  updateGoodPhoto,
  deleteGoodPhoto
} = require('../../controller/photo')

router.prefix('/jihuide/photo')

// 添加商品图片信息
router.post('/addGoodPhoto', async (ctx, next) => {
  let { goodsInfoId, photoName, photoUrl } = ctx.request.body
  goodsInfoId = parseInt(goodsInfoId)
  // 接下来交给控制层
  ctx.body = await addGoodPhoto({
    goodsInfoId,
    photoName,
    photoUrl,
  })
})

// 查询所有商品图片信息
router.post('/getGoodPhotosAll', async (ctx, next) => {
  let { id, page, limit } = ctx.request.body
  id = parseInt(id)
  // 接下来交给控制层
  ctx.body = await getGoodPhotosAll({
    id,
    page,
    limit,
  })
})

// 修改商品图片信息
router.post('/updateGoodPhoto', async (ctx, next) => {
  let { id, photoName, photoUrl } = ctx.request.body
  id = parseInt(id)
  // 接下来交给控制层
  ctx.body = await updateGoodPhoto({
    id,
    photoName,
    photoUrl,
  })
})

// 删除商品信息
router.post('/deleteGoodPhoto', async (ctx, next) => {
  let { id } = ctx.request.body
  id = parseInt(id)
  // 接下来交给控制层
  ctx.body = await deleteGoodPhoto(id)
})

module.exports = router
